package org.excilys.training.ebanking.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.joda.time.DateTime;

@Entity
@Table(name = "OPERATIONS")
public class Operation {

	private int id;

	private Compte compte;

	private int compteDestinataire;

	private String libelle;

	private double montant;

	private DateTime dateOperation;

	private TypeOperation typeOperation;

	private DateTime dateEffective;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name = "compte")
	public Compte getCompte() {
		return compte;
	}

	public void setCompte(Compte compte) {
		this.compte = compte;
	}

	@Column(name = "compte_destinataire")
	public int getCompteDestinataire() {
		return compteDestinataire;
	}

	public void setCompteDestinataire(int compteDestinataire) {
		this.compteDestinataire = compteDestinataire;
	}

	public String getLibelle() {
		return libelle;
	}

	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}

	public double getMontant() {
		return montant;
	}

	public void setMontant(double montant) {
		this.montant = montant;
	}

	@Column(name = "date_operation")
	public org.joda.time.DateTime getDateOperation() {
		return dateOperation;
	}

	public void setDateOperation(org.joda.time.DateTime dateOperation) {
		this.dateOperation = dateOperation;
	}

	@ManyToOne
	@JoinColumn(name = "id_type_operation")
	public TypeOperation getTypeOperation() {
		return typeOperation;
	}

	public void setTypeOperation(TypeOperation typeOperation) {
		this.typeOperation = typeOperation;
	}

	@Transient
	public DateTime getDateEffective() {
		return dateEffective;
	}

	public void setDateEffective(DateTime dateEffective) {
		this.dateEffective = dateEffective;
	}

	public static class Builder {
		Operation operation;

		public Builder() {
			operation = new Operation();
		}

		public Builder withCompteDestinataire(int compteDestinataire) {
			operation.setCompteDestinataire(compteDestinataire);
			return this;
		}

		public Builder withLibelle(String libelle) {
			operation.setLibelle(libelle);
			return this;
		}

		public Builder withMontant(double montant) {
			operation.setMontant(montant);
			return this;
		}

		public Builder withDateOperation(DateTime dateOperation) {
			operation.setDateOperation(dateOperation);
			return this;
		}

		public Builder withtypeOperation(TypeOperation typeOperation) {
			operation.setTypeOperation(typeOperation);
			return this;
		}

		public Builder withCompte(Compte compte) {
			operation.setCompte(compte);
			return this;
		}

		public Operation build() {
			return operation;
		}
	}

}
